<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0050)http://otter-rsch.com/admbre/examples/nbmm/nbmm.html -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2604" name=GENERATOR></HEAD>
<BODY><BR>
<TABLE cellSpacing=2 cellPadding=2 align=center border=0>
  <TBODY>
  <TR>
    <TD align=middle colSpan=2>
      <DIV align=center>
      <H1>Negative Binomial Loglinear Mixed Model</H1></DIV><BR><BR></TD></TR>
  <TR>
 
    <TD width="30%">
      <TABLE cellSpacing=0 cellPadding=2 width="90%" bgColor=#359163 border=0>
        <TBODY>
        <TR>
          <TD align=middle><FONT face="Arial, Helvetica" color=white><B>ADMB 
            Files</B></FONT> </TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff 
            border=0>
              <TBODY>
              <TR>
                <TD>Code: <A href="nbmm.tpl">nbmm.tpl</A><BR>
				  NOTE: This model does not compile under the current demo version of ADMB-RE, but
				  will do with the next version.<br>
				  <br>
				  
				  Data: <A href="nbmm.dat">nbmm.dat</A><BR>Initial 
                  values: <A 
                  href="nbmm.pin">nbmm.pin</A><!--<BR>All 
                  required files (DOS): <A 
                  href="nbmm.zip">nbmm.zip</A><BR> -->
				  Expected Results: 
                  <A 
                  href="nbmm.par">nbmm-expected-results.par</A><BR></FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<!--
      <TABLE cellSpacing=0 cellPadding=2 width="90%" bgColor=#359163 border=0>
        <TBODY>
        <TR>
          <TD align=middle><FONT face="Arial, Helvetica" 
            color=white><B>Running ADMB-executables</B></FONT> </TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff 
            border=0>
              <TBODY>
              <TR>
                <TD>In a <A 
                  href="../admb_tutorial.html">DOS</A> 
                  window<BR> Under <A 
                  href="../admb_tutorial.html">linux</A> 
        </FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
-->
      <TABLE cellSpacing=0 cellPadding=2 width="90%" bgColor=#359163 border=0>

        <TR>
          <TD align=middle><FONT face="Arial, Helvetica" 
            color=white><B>Calling ADMB-RE from R </B></FONT> </TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff 
            border=0>
              <TBODY>
              <TR>
                <TD>			  
                         AD model Builder has existed for years as a program to produce stand alone executables on Winows and Linux. Modifying it to seamlessly produce shared libraries for R can be expected to produce a few wrinkles so 
 please be patient and give us feedback.<p>
			 To run the examples in R you need to download (and source into R) the file
			  <A href="glmmadmb.s">glmmadmb.s</A> which defines the driver
			  function <TT>glmm.admb()</TT> and a modified versions "epil2" of the epil-dataset from MASS.
              You also need to download the library file (<A href="nbmm.dll">nbmm.dll</A> if you
			  run Windows, or <A href="nbmm.so">nbmm.so</A>
 if you run Linux) and save it in
			  the directory where you run R.
			  <br>
			  <br>
			  You should note that the ADMB-RE executables create temporary files (sometimes large), so you should probably start R in a 
			  specially dedicated directory. 
			  <br>
			  <br>
              Standard deviations of parameter estimates can be found in the file "nbmm.std"

        </FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
      <TABLE cellSpacing=0 cellPadding=2 width="90%" bgColor=#359163 border=0>


        <TR>
          <TD align=middle><FONT face="Arial, Helvetica" 
            color=white><B>Navigation</B></FONT> </TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff 
            border=0>
              <TBODY>
              <TR>
                <TD>			  
				<A href="http://otter-rsch.com/admbre/admbre.html">ADMB-RE home</A> <br>
                <A href="http://otter-rsch.com/">Otter Research</A> 

        </FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
      <TABLE cellSpacing=0 cellPadding=2 width="90%" bgColor=#359163 border=0></TABLE>


   </TD>
				
    <TD width="75%">
      <H3><STRONG>Model description</STRONG></H3>
	  
	  The negative binomial distribution can be used instead of the Poisson distribution to investigate whether 
      there is overdispersion in the data, that is whether the variance of the 
      observations is greater than that which would be expected for a Poisson 
      distribution. Parameter estimation for such models is 
      generally claimed to be difficult. See for example <A 
      href="https://stat.ethz.ch/pipermail/r-help/2005-February/064708.html">R-help</A> 
      the mailing list archives of the statistical modeling language R. The data 
      used in this example are the epilepsy data considered in Venables and 
      Ripley <A href="http://www.stats.ox.ac.uk/pub/MASS4/">Modern applied 
      statics with S 4th edition.</A> and by Booth et al. <A 
      href="http://www.stat.tugraz.at/friedl/papers/negbin.ps">Negative Binomial 
      Loglinear Mixed Models</A>. 
	  
	  <H3><STRONG>Implementation in ADMB-RE callable from <A href="http://www.r-project.org/">R</A></STRONG></H3>
   
      We coded up the model in ADMB-RE (<TT><A href="nbmm.tpl">nbmm.tpl</A></TT>)
	  with flexible linear predictors for both fixed and random effects. The program was then compiled into a DLL that can be called from R
	  via the R-function <TT>glmm.admb()</TT>. Examples of how to use this function are given below. Currently <TT>glmm.admb()</TT>
	  only allows negative binomial, but implementing other distributions like Bernoulli and Poisson is just a question of adding
	  a few lines of code to <TT>nbmm.tpl</TT>.
	  
      <H3><STRONG>Comparison with SAS NLMIXED</STRONG></H3>Booth et al. attempt 
      to fit two negative binomial loglinear mixed models to the data. They refer to these models as the full model and a simpler model. 
	  For the full model they report<B>:</B> 
      <P>
      <TABLE><I>The fit of the full negative binomial model using NLMIXED was 
        very unstable. Different starting values led to different estimates and 
        very different standard errors. </I>
        <TBODY></TBODY></TABLE>
      <P>Booth et al also apply a Monte Carlo EM algorithm (MCEM) to the full model and report<B>:</B> 
      <P>
      <TABLE><I>Application of the MCEM algorithm in this problem suggest that 
        the random slope is 0. The MCEM algorithm was run for a large number of 
        iterations with all of the estimates except for slope variance and the 
        covariance converging quickly. These latter two estimates appear to be 
        slowly converging toward 0. </I>
        <TBODY></TBODY></TABLE>
      <P>
	  The full model of Booth et al. is specified as: <br><br
	  <TT>glmm.admb(y~Base*trt+Age+Visit,random=~Visit,group="subject",data=epil2)</TT><br>
	  <br>
	  This model converges quickly (30 seconds), with the ML estimate of the variance of the random slope being equal to zero (or extremely small), 
	  and as a consequence of this there is very little information about the correlation parameter (between the random intercept and the slope). 
	  <!--We calculated the profile likelihood for the correlation parameter and found a difference in the log-likelihood of only about 0.2 between the 
	  extremes of <TT>-1</TT> and <TT>+1</TT>, with the maximum occuring at the boundary of <TT> -1.</tt> -->
          The standard eviations of the parameter estimates including those of the random effects are found in the file nbmm.std. 
	  
	  We also fitted the simpler model of Booth et al.: <br><br
	  <TT>glmm.admb(y~Base*trt+Age+Visit,random=~1,group="subject",data=epil2)</TT><br>
	  <br>
	  This model converged quickly (15 seconds) to the ML estimates. We used different starting 
      values to investigate the stability of the model and found that it  converged to the same values each time (provided that the chosen 
	  initial values exceeded a minimum level of overdispersion).
	  Thus it appears that the performance of ADMB-RE is superior to SAS NLMIXED for this problem. 
     
	  </TD><BR>  </TR></TBODY></TABLE></BODY></HTML>
